package com.tomatozq163.receiver;

import com.rabbitmq.client.Channel;
import com.tomatozq163.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@RabbitListener(queues = "vehicleStopQueue")
public class TTLReceiver {
    @RabbitHandler
    public void handle(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag){
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
            Date now = new Date();

            System.out.println("接收消息时间：" + sdf.format(now));
            System.out.println("接收消息内容：" + msg);

            //basicAck(long deliveryTag, boolean multiple)
            channel.basicAck(tag, false);
        }
        catch(Exception ex){
            ex.printStackTrace();
        }
    }
}
